package scheduler

import "spider/concurrent2/parser"

type SimpleScheduler struct {
    workerChan chan  parser.Request
}

func (SimpleScheduler *SimpleScheduler) WorkerRequestChan() chan parser.Request {
    return  SimpleScheduler.workerChan
}

func (SimpleScheduler *SimpleScheduler) WorkerReady(chan parser.Request) {
}

func (SimpleScheduler *SimpleScheduler) Run() {
    SimpleScheduler.workerChan = make(chan  parser.Request)
}

// 设置调度器分发任务的channel
// func (SimpleScheduler *SimpleScheduler) SetMasterWorkerChan(masterWorkerChan chan parser.Request) {
//     SimpleScheduler.workerChan = masterWorkerChan
// }

// 提交request给调度器
func (SimpleScheduler *SimpleScheduler) Submit(request parser.Request)  {
    // 使用goroutine解决无空闲worker接收channel时,
    // 产生循环等待的问题
    go func() {
        // 将request发送到worker channel
        SimpleScheduler.workerChan <- request
    }()
}
